<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- 以借助 script 标签直接通过 CDN 来使用 Vue： -->
    <script src="./JS/vue.global.js"></script>
  </head>
  <body>
    <div id="app">
      <!-- 遍历数组 -->
      <button @click="add">添加一个老刘</button>
      <ul>
        <li v-for="(p,index) of persons" :key="p.id">
          {{p.name}}-{{p.age}} <input type="text" />
        </li>
      </ul>
    </div>

    <script>
      Vue.createApp({
        data() {
          return {
            persons: [
              {
                id: "001",
                name: "张三",
                age: 19,
              },
              {
                id: "002",
                name: "李四",
                age: 18,
              },
              {
                id: "003",
                name: "王五",
                age: 15,
              },
            ],
          };
        },
        methods: {
          add() {
            const p = { id: "004", name: "老刘", age: 40 };
            this.persons.unshift(p);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
